import { BroadCastCall } from "../../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SSeqSStallLeaveWord } from "../../../../../Message/Public/SSeqSStallLeaveWord";
import { EntityUtil } from "../../../scene/layer/utils/EntityUtil";
import { Cache } from "../../../cache/Cache";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
//class StallLeaveWordUpdate
    
    export  class StallLeaveWordUpdate extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            super.call(arg1);
            var loc1=arg1.messageBase as SSeqSStallLeaveWord;
            if (EntityUtil.toString(loc1.updateEntityId) != EntityUtil.toString(Cache.instance.role.entityInfo.entityId)) 
            {
                if (EntityUtil.toString(loc1.updateEntityId) == EntityUtil.toString(Cache.instance.stallOtherCache.entityId)) 
                {
                    if (loc1.leaveWords.length > 0) 
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.StallOtherLeaveWordsUpdate, loc1.leaveWords);
                    }
                    else 
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.StallOtherLeaveWordsClear, null);
                    }
                }
            }
            else if (loc1.leaveWords.length == 0) 
            {
                Cache.instance.pack.stallPackCache.clearLeaveWords();
                NetDispatcher.dispatchCmd(ServerCommand.StallSelfLeaveWordsClear, null);
            }
            else 
            {
                Cache.instance.pack.stallPackCache.addLeaveWords(loc1.leaveWords);
                NetDispatcher.dispatchCmd(ServerCommand.StallSelfLeaveWordsUpdate, loc1.leaveWords);
            }
            return;
        }
    }
